A1 = readmatrix('NiI2_repearable_switch_30K.txt')

x = A1(:,1)
y = A1(:,2)*1e12+0.15
x1 = []
y1 = []
count = 0

for m = 1:10
    count = count + 1
    x1 = [x1;count]
    y1 = [y1;0]
end

for i = 1:10
    for k = 1:30
        count = count + 1
        x1 = [x1;count]
        y1 = [y1;0]
    end
        for j = 1:10
        count = count + 1
        x1 = [x1;count]
        y1 = [y1;y(i*10-10+j)]
    end
end

for m = 1:10
    count = count + 1
    x1 = [x1;count]
    y1 = [y1;0]
end

x2 = []
y2 = []
count = 0
for m = 1:15
    count = count + 1
    x2 = [x2;count]
    y2 = [y2;0]
end

for i = 1:10
    for k = 1:5
        count = count + 1
        x2 = [x2;count]
        y2 = [y2;0]
    end
    for j = 1:35
        count = count + 1
        x2 = [x2;count]
        y2 = [y2;1]
    end
end

for m = 1:5
    count = count + 1
    x2 = [x2;count]
    y2 = [y2;0]
end

x3 = []
y3 = []
count = 0
for m = 1:15
    count = count + 1
    x3 = [x3;count]
    y3 = [y3;0]
end

for i = 1:5
    for k = 1:5
        count = count + 1
        x3 = [x3;count]
        y3 = [y3;-12]
    end
    for j = 1:35
        count = count + 1
        x3 = [x3;count]
        y3 = [y3;0]
    end
    for k = 1:5
        count = count + 1
        x3 = [x3;count]
        y3 = [y3;12]
    end
    for j = 1:35
        count = count + 1
        x3 = [x3;count]
        y3 = [y3;0]
    end
end

for m = 1:5
    count = count + 1
    x3 = [x3;count]
    y3 = [y3;0]
end

x1 = x1*2
x2 = x2*2
x3 = x3*2

data = cat(2,x1,y1,y2,y3)
writematrix(data,'switchtest.txt')

subplot(3,1,3,'Position',[0.15 0.1 0.8 0.3])
hold on
scatter(x1,y1,5,'filled','MarkerFaceColor',[0.2 0 0.8])
plot(x1,y1,'Linewidth',1,'Color',[0.2 0 0.8])
ylim([-2.5,2.5])
yticks(-2:2:2)
xlabel('Time [s]')
ylabel('Photocurrent [pA]')
set(gca,'box','on')
hold off

subplot(3,1,2,'Position',[0.15 0.4 0.8 0.1])
hold on
plot(x2,y2,'Linewidth',1,'Color',[0.4 0.6 0])
ylim([-0.2,1.2])
xticklabels([])
yticks(0:1:1)
ylabel('Laser')
set(gca,'box','on')
hold off

subplot(3,1,1,'Position',[0.15 0.5 0.8 0.15])
hold on
plot(x3,y3,'Linewidth',1,'Color',[0.8 0 0.2])
ylim([-13,13])
yticks(-12:12:12)
xticklabels([])
ylabel('Electric Field [MV/m]')
set(gca,'box','on')
hold off
box on

set(gcf,'Position',[0, 0, 200, 300])